FROM python:3.12-slim-bullseye as builder
RUN apt-get update && apt-get install -y git gcc curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && apt-get install --reinstall libc6-dev -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN pip install --upgrade pip && pip install tiktoken==0.5.1

FROM python:3.12-slim-bullseye

ARG LISTEN_PORT=8501
ENV PORT=$LISTEN_PORT

WORKDIR /app

COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/

RUN apt-get update && apt-get install -y git gcc

COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
# RUN pip install --no-cache-dir --index-url https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r requirements.txt

COPY ./app /app

EXPOSE $PORT

# ENTRYPOINT [ "streamlit", "run", "bot.py", "--server.port=$PORT" ]
ENTRYPOINT streamlit run bot.py --server.port=$PORT
